package com.gnerv.sylvanas.business.manage.logic;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.framework.core.BaseUkIdGenerate;
import com.gnerv.sylvanas.business.manage.model.bo.ConfigBO;
import com.gnerv.sylvanas.business.manage.model.dto.ConfigCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ConfigDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ConfigUpdateDTO;
import com.gnerv.sylvanas.business.manage.operation.ConfigOperationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class ConfigLogicService  {

    private final ConfigOperationService configService;
    private final BaseUkIdGenerate baseUkIdGenerate;

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> create(ConfigCreateDTO configCreateDTO) {
        ConfigBO configBO = configCreateDTO.toConfigBO();
        configBO.setUkId(baseUkIdGenerate.generate());
        configService.create(configBO);
        return RestResult.ok();
    }

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> deleteByUkId(String ukId) {
        configService.deleteByUkId(ukId);
        return RestResult.ok();
    }

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> updateByUkId(ConfigUpdateDTO configUpdateDTO) {
        configService.updateByUkId(configUpdateDTO.toConfigBO());
        return RestResult.ok();
    }

    
    @Transactional(readOnly = true)
    public RestResult<ConfigDTO> selectByUkId(String ukId) {
        return RestResult.ok(configService.selectByUkId(ukId));
    }

    
    @Transactional(readOnly = true)
    public RestResult<List<ConfigDTO>> selectListByName(String name) {
        return RestResult.ok(configService.selectListByName(name));
    }

}
